* WAVE 1 Mexico
* 2000-2003

clear all
cd "/Users/chuangchen/Library/CloudStorage/OneDrive-UniversityofPittsburgh/Pela project/PELA DATA/Mexico/Mexico_analyze/"
import spss using "BASEDATOS_MEXICO_37.sav"

keep nestu pais partido legis p34a p3501 p3502 p3503 p3504 p3505 p3507 p3508 p3509 p3510 p40 p42 p67 p68 p69 p70 p71 p72 p73 p74 p76

elabel variable (*) ("")

label variable nestu "Study number"
label variable pais "Country name"
label variable legis "Legislature"

label drop labels0
label values pais
tostring pais, replace
replace pais="Mexico"

replace legis=2003

gen party = "."
replace party = "MX_PAN" if partido ==1
replace party = "MX_PRD" if partido ==2
replace party = "MX_PRI" if partido ==3
replace party = "MX_Other" if partido ==8

drop partido 

rename party partido
label variable partido "Party name"

label variable p67 "Ideology"
rename p67 ID1
replace ID1 = . if ID1 > 10
label variable p68 "Ideology of your party"
rename p68 ID2
replace ID2 = . if ID2 > 10

label variable p71 "Female (dummy 1 if woman)"
rename p71 female
recode female (1=0)(2=1)
label define female_label 1 "female" 0 "male"
label value female female_label

gen rel_catholic=1 if p69==1
replace rel_catholic=0 if rel_catholic!=1
label variable rel_catholic "Catholic (dummy 1 if catholic)"
label define rel_cath_lab 1 "Catholic" 0 "Other"
label value rel_catholic rel_cath_lab

gen rel_other=1 if p69==2
replace rel_other=0 if rel_other!=1
label variable rel_other "Religious Other (dummy 1 if other)"
label define rel_other_lab 1 "Other" 0 "Evangelical/Catholic"
label value rel_other rel_other_lab

rename p69 religious
recode religious (4 5=0)(1 2=1)
replace religious = . if religious == 9
label variable religious "Religious (dummy 1 if believer)"
label define religious_label 1 "believer" 0 "nonbeliever"
label value religious religious_label

rename p70 church_attend
replace church_attend=. if church_attend>5
label variable church_attend "Attendance to the church"

label variable p72 "Age (years)"
rename p72 age
replace age = . if age == 99

rename p76 education
label variable education "Highest level of education"
replace education = . if education > 6

* Attention: 1-5 scale, 5 is against
rename p74 val_abortion
recode val_abortion (1=5)(2=4)(3=3)(4=2)(5=1)
label variable val_abortion "Opinion about abortion"
label drop labels68
replace val_abortion = . if val_abortion > 5
replace val_abortion = val_abortion*2

* Attention: 1-5 scale
rename p73 val_divorce
recode val_divorce (1=5)(2=4)(3=3)(4=2)(5=1)
label variable val_divorce "Opinion about divorce"
label drop labels67
replace val_divorce = . if val_divorce > 5
replace val_divorce = val_divorce*2

rename p34a eco_regulated
label variable eco_regulated "Regulate Economy"
label drop labels32
replace eco_regulated = . if eco_regulated > 5
replace eco_regulated = eco_regulated*2
* attention to the rescaling
                                                          
rename p3501 eco_prices
label variable eco_prices "Price control"
label drop labels31
recode eco_prices (1=4)(2=3)(3=2)(4=1)
replace eco_prices=. if eco_prices>4

rename p3502 eco_education_p
label variable eco_education_p "Free primary education"
recode eco_education_p (1=4)(2=3)(3=2)(4=1)
replace eco_education_p=. if eco_education_p>4

rename p3503 eco_housing
label variable eco_housing "Subsidize housing"
replace eco_housing=. if eco_housing>4
recode eco_housing (1=4)(2=3)(3=2)(4=1)


rename p3504 eco_employment
label variable eco_employment "Employment creation"
replace eco_employment = . if eco_employment > 7
recode eco_employment (4=1) (3=3) (2=5) (1=7)


rename p3505 eco_education_s
label variable eco_education_s "Free secondary education"
recode eco_prices (1=4)(2=3)(3=2)(4=1)

rename p3507 eco_education_u 
label variable eco_education_u "Free university education"
replace eco_education_u = . if eco_education_u > 7
recode eco_education_u (4=1) (3=3) (2=5) (1=7)


rename p3508 eco_unemployment
label variable eco_unemployment "Unemployment insurance"
replace eco_unemployment = . if eco_unemployment > 4
recode eco_unemployment (1=4)(2=3)(3=2)(4=1)


rename p3509 eco_environment
replace eco_environment = . if eco_environment > 4
recode eco_environment (1=4)(2=3)(3=2)(4=1)


rename p3510 eco_necessity
replace eco_necessity = . if eco_necessity > 4
recode eco_necessity (1=4)(2=3)(3=2)(4=1)


rename p40 eco_tax
replace eco_tax=. if eco_tax > 2
label variable eco_tax "Whether legislator prefers direct or indirect taxes"
label define tax_lab 1 "direct" 2 "indirect"
label value eco_tax tax_lab

* Attention to the scale
rename p42 eco_private
label variable eco_private "Whether the state should privatize state industries"
replace eco_private =. if eco_private >5


gen wave = 1

save "Mexico_wave1.dta", replace


**************************************

* WAVE 2 Mexico
* 2003-2006

* Very similar to Chile 2002-2006
**************************************
clear all
import spss using "BASEDATOS_MEXICO_50.SAV"
keep nestu pais partido legis p58 p59 p60 p60a p62 p63 p67 p65 p28 p64 p34 p2901 p2902 p2903 p2904 p2905 p2906 p2907 p2908 p2909 p2910

elabel variable (*) ("")

label variable nestu "Study number"
label variable pais "Country name"
label variable legis "Legislature"

label drop labels0
label values pais
tostring pais, replace
replace pais="Mexico"

replace legis=2006 

gen party = "."
replace party = "MX_PAN" if partido ==1
replace party = "MX_PRD" if partido ==2
replace party = "MX_PRI" if partido ==3
replace party = "MX_Other" if partido ==4

drop partido 

rename party partido
label variable partido "Party name"

label variable p58 "Ideology"
rename p58 ID1
replace ID1 = . if ID1 > 10
label variable p59 "Ideology of your party"
rename p59 ID2
replace ID2 = . if ID2 > 10

label variable p62 "Female (dummy 1 if woman)"
rename p62 female
recode female (1=0)(2=1)
label define female_label 1 "female" 0 "male"
label value female female_label

rename p60 religious
recode religious (2=0)
replace religious=. if religious > 2
label variable religious "Religious (dummy 1 if believer)"
label define religious_label 1 "believer" 0 "nonbeliever"
label value religious religious_label

gen rel_evangelical=1 if p60a==3
replace rel_evangelical=0 if rel_evangelical!=1
label variable rel_evangelical "Evangelical (dummy 1 if evangelical)"
label define rel_evan_lab 1 "Evangelical" 0 "Other"
label value rel_evangelical rel_evan_lab

gen rel_catholic=1 if p60a==1
replace rel_catholic=0 if rel_catholic!=1
label variable rel_catholic "Catholic (dummy 1 if catholic)"
label define rel_cath_lab 1 "Catholic" 0 "Other"
label value rel_catholic rel_cath_lab

* attention: choice 9
gen rel_other=1 if p60a!=1 & p60a!=3
replace rel_other=0 if rel_other!=1
label variable rel_other "Religious Other (dummy 1 if other)"
label define rel_other_lab 1 "Other" 0 "Evangelical/Catholic"
label value rel_other rel_other_lab

drop p60a

* no question about church attendance
* rename p60b religiosity

label variable p63 "Age (years)"
rename p63 age
replace age = . if age == 99

rename p67 education
label variable education "Highest level of education"
replace education = . if education > 6

* 10 is in favor
rename p65 val_abortion
label variable val_abortion "Opinion about abortion"
replace val_abortion = . if val_abortion > 10

rename p64 val_divorce
label variable val_divorce "Opinion about divorce"
replace val_divorce = . if val_divorce > 10

rename p28 eco_regulated
label variable eco_regulated "Regulate Economy"
label drop labels32
replace eco_regulated = . if eco_regulated > 5
replace eco_regulated = eco_regulated*2
* attention to the rescaling

rename p34 eco_tax
label variable eco_tax "Whether legislator prefers direct or indirect taxes"
label define tax_lab 1 "direct" 2 "indirect" 3 "no more tax"
label value eco_tax tax_lab                                                             
rename p2901 eco_prices
label variable eco_prices "Price control"
replace eco_prices = . if eco_prices > 4

rename p2902 eco_education_p
label variable eco_education_p "Free primary education"
replace eco_education_p = . if eco_education_p > 4
* combines primary and secondary education

rename p2907 eco_education_u 
label variable eco_education_u "Free university education"
replace eco_education_u = . if eco_education_u > 7
recode eco_education_u (1=1) (2=3) (3=5) (4=7)


rename p2903 eco_housing
label variable eco_housing "Subsidize housing"
replace eco_housing = . if eco_housing > 4

rename p2904 eco_employment
label variable eco_employment "Employment creation"
replace eco_employment = . if eco_employment > 7
recode eco_employment (1=1) (2=3) (3=5) (4=7)


rename p2906 eco_health
label variable eco_health "Whether the state should provide health services"
replace eco_health = . if eco_health > 7
recode eco_health (1=1) (2=3) (3=5) (4=7)


rename p2908 eco_unemployment
label variable eco_unemployment "Unemployment insurance"
replace eco_unemployment = . if eco_unemployment > 4

rename p2905 eco_pensions
label variable eco_pensions "Pension"
replace eco_pensions = . if eco_pensions > 7
recode eco_pensions (1=1) (2=3) (3=5) (4=7)


rename p2909 eco_environment
replace eco_environment = . if eco_environment > 4

rename p2910 eco_necessity
replace eco_necessity = . if eco_necessity > 4

gen wave = 2

save "Mexico_wave2.dta", replace

**************************************

* WAVE 3 Mexico
* 2006-2009
* Very similar to Chile 2006-2010
**************************************

clear all
import spss using "BASEDATOS_MEXICO_63.SAV"
keep nestu pais legis partido p28 p33 p35 p64 p65 p66 p66a p67 p68 p69 p70 p73 p2901-p2907

elabel variable (*) ("")

label variable nestu "Study number"
label variable pais "Country name"
label variable legis "Legislature"

label drop labels0
label values pais
tostring pais, replace
replace pais="Mexico"

replace legis=2009

gen party = "."
replace party = "MX_PAN" if partido ==1
replace party = "MX_PRD" if partido ==2
replace party = "MX_PRI" if partido ==3
replace party = "MX_Other" if partido ==4

drop partido 

rename party partido
label variable partido "Party name"

label variable p64 "Ideology"
rename p64 ID1
replace ID1 = . if ID1 > 10
label variable p65 "Ideology of your party"
rename p65 ID2
replace ID2 = . if ID2 > 10

label variable p67 "Female (dummy 1 if woman)"
rename p67 female
recode female (1=0)(2=1)
label define female_label 1 "female" 0 "male"
label value female female_label

rename p66 religious
recode religious (2=0)
replace religious=. if religious > 2
label variable religious "Religious (dummy 1 if believer)"
label define religious_label 1 "believer" 0 "nonbeliever"
label value religious religious_label

gen rel_evangelical=1 if p66a==3
replace rel_evangelical=0 if rel_evangelical!=1 & rel_evangelical!=.
label variable rel_evangelical "Evangelical (dummy 1 if evangelical)"
label define rel_evan_lab 1 "Evangelical" 0 "Other"
label value rel_evangelical rel_evan_lab

gen rel_catholic=1 if p66a==1
replace rel_catholic=0 if rel_catholic!=1 & rel_catholic!=.
label variable rel_catholic "Catholic (dummy 1 if catholic)"
label define rel_cath_lab 1 "Catholic" 0 "Other"
label value rel_catholic rel_cath_lab

gen rel_other=1 if p66a != 1 & p66a != 3 & p66a < 6
replace rel_other=. if p66a > 5
replace rel_other=0 if rel_other!=1 & rel_other!=.
label variable rel_other "Religious Other (dummy 1 if other)"
label define rel_other_lab 1 "Other" 0 "Evangelical/Catholic"
label value rel_other rel_other_lab

drop p66a

* no question about church attendance
* rename p6bb religiosity

label variable p68 "Age (years)"
rename p68 age
replace age = . if age == 99

rename p73 education
label variable education "Highest level of education"
replace education = . if education > 6

rename p70 val_abortion
label variable val_abortion "Opinion about abortion"
replace val_abortion = . if val_abortion > 10

rename p69 val_divorce
label variable val_divorce "Opinion about divorce"
replace val_divorce = . if val_divorce > 10

rename p28 eco_regulated
label variable eco_regulated "Regulate Economy"
label drop labels32
replace eco_regulated = . if eco_regulated > 5
replace eco_regulated = eco_regulated*2
* attention to the rescaling

rename p33 eco_tax
replace eco_tax=. if eco_tax > 2
label variable eco_tax "Whether legislator prefers direct or indirect taxes"
label define tax_lab 1 "direct" 2 "indirect"
label value eco_tax tax_lab                                                             

rename p2901 eco_prices
label variable eco_prices "Price control"

rename p2902 eco_education_p
label variable eco_education_p "Free primary education"
* combines primary and secondary education

rename p2907 eco_education_u 
label variable eco_education_u "Free university education"
replace eco_education_u = . if eco_education_u > 7
recode eco_education_u (1=1) (2=3) (3=5) (4=7)


rename p2903 eco_housing
label variable eco_housing "Subsidize housing"

rename p2904 eco_employment
label variable eco_employment "Employment creation"
replace eco_employment = . if eco_employment > 7
recode eco_employment (1=1) (2=3) (3=5) (4=7)


rename p2906 eco_health
label variable eco_health "Whether the state should provide health services"
replace eco_health = . if eco_health > 7
recode eco_health (1=1) (2=3) (3=5) (4=7)


rename p2905 eco_pensions
label variable eco_pensions "Pension"
replace eco_pensions = . if eco_pensions > 7
recode eco_pensions (1=1) (2=3) (3=5) (4=7)


rename p35 eco_natural
label variable eco_natural "Natural resources"
replace eco_natural = . if eco_natural > 5

gen wave = 3

save "Mexico_wave3.dta", replace

********************************************

* WAVE 4 Mexico
* 2009-2012
* Very similar to Chile 2014-2018
* Adapted from Valentina

*****************************************************************
{
clear
*Calling the data 2009-2012
import spss using "BASEDATOS_MEXICO_79.sav", clear 
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
 /*
 

 */

*drop all labels
elabel variable (*) ("")

label drop labels0
label values pais
tostring pais, replace
replace pais="Mexico"

drop legis 
gen legis = 2011

* Ideology 
replace ID1=. if  ID1>11
* Ideology Party
replace ID2=. if  ID2>11


// Attendance to church
gen church_attend=RE1B

gen regular=1 if RE1B==3 | RE1B==4 | RE1B==5
replace regular=0 if RE1B==1 | RE1B==2 

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "MX_PRI" if partido ==1
replace party = "MX_PAN" if partido ==2
replace party = "MX_PRD" if partido ==3
replace party = "MX_VERDE" if partido ==4
replace party = "MX_PT" if partido ==5
replace party = "MX_Nueva Allianza" if partido ==6
replace party = "MX_Convergencia" if partido ==7
replace party = "MX_Other" if partido > 7

drop partido 

gen partido=party

*--------------------------
* Abortion
*--------------------------
replace VAL2 =. if VAL2>10
gen VAL2_2=VAL2
gen val_abortion=round(VAL2_2)
lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221


*--------------------------
* SSM
*--------------------------
replace VAL1 =. if VAL1>10
gen val_ssm=VAL1
lab define VAL1 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_ssm VAL1

*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious=1 if RE1==1
replace religious=0 if RE1==2
replace religious=. if RE1>2

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if RE1A==4
replace rel_evangelical=0 if religious==1 & rel_evangelical==1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if RE1A==1
replace rel_catholic=0 if religious==1 & rel_catholic==1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=.
replace rel_other=1 if religious==1 & rel_evangelical!=1 & rel_catholic!=1

*--------------------------
* Education
*--------------------------
gen education= SOCD7 if  SOCD7<9


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if SOCD4==2
replace female=0 if SOCD4==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=SOCD5 if SOCD5<100

*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=EM1
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=ROES107 if  ROES107<8
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* State should reduce inequality
*-----------------------
gen eco_inequaltiy=ROES104  if  ROES104<8

lab val eco_inequaltiy eco_education_u

*-----------------------
* State should create employment
*-----------------------
gen eco_employment=ROES103   if  ROES103 <8

lab val eco_employment eco_education_u

*-----------------------
* State companies
*-----------------------
gen eco_companies=ROES101    if  ROES101  <8

lab val eco_companies eco_education_u

*-----------------------
* State wellbeing
*-----------------------
gen eco_wellbeing=ROES102     if  ROES102   <8

lab val eco_wellbeing eco_education_u

*-----------------------
* State health
*-----------------------
gen eco_health=ROES106      if  ROES106    <8

lab val eco_health eco_education_u

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=ROES105       if  ROES105     <8

lab val eco_pensions eco_education_u

*-----------------------
* Natural resources
*-----------------------
rename PRIV2 eco_natural
label variable eco_natural "Natural resources"
replace eco_natural = . if eco_natural > 10
replace eco_natural = eco_natural/2

*-----------------------
* Tax reform
*-----------------------

rename IMP1A eco_tax
replace eco_tax=. if eco_tax > 2
label variable eco_tax "Whether legislator prefers direct or indirect taxes"
label define tax_lab 1 "direct" 2 "indirect"
label value eco_tax tax_lab


}

// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_pensions "Pension"
lab var eco_health "Whether the state should own provide health services  (1, 7 in favor)"
lab var eco_wellbeing "Whether the state should guarantee basic wellbeign  (1, 7 in favor)"
lab var eco_companies "Whether the state should own companies  (1, 5)"
lab var eco_natural "Level of control the State should have over natural resources)"
lab var eco_tax "Whether legislator prefers direct or indirect taxes"

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep nestu pais partido legis ID1 ID2 church_attend religious rel_evangelical rel_catholic rel_other val_abortion val_ssm eco_regulated education female age eco_inequaltiy eco_education_u eco_employment eco_pensions eco_health eco_wellbeing eco_natural eco_tax

}

gen wave = 4

*****************************************************************
* Save
***************************************************************** 
save "Mexico_wave4.dta", replace
}
*****************************************************************
* Append
***************************************************************** 
{
clear all
append using "Mexico_wave1.dta"
append using "Mexico_wave2.dta"
append using "Mexico_wave3.dta"
append using "Mexico_wave4.dta"

save "Mexico.dta", replace
*****************************************************************
}


